package common

import (
	"github.com/prometheus/client_golang/prometheus"
	"time"
)

type Metric interface {
	SetValueWithTs(float64, time.Time)
	Get() *metric
	GetMetricName() string
}

type metric struct {
	Name  string
	Value float64
	Desc  *prometheus.Desc
	Time  time.Time
}

func NewMetric(name string, desc *prometheus.Desc) Metric {
	return &metric{
		Name:  name,
		Value: 0,
		Desc:  desc,
		Time:  time.Now(),
	}
}

func (m *metric) SetValueWithTs(v float64, t time.Time) {
	m.Value = v
	m.Time = t
}

func (m *metric) Get() *metric {
	return m
}

func (m *metric) GetMetricName() string {
	return m.Name
}
